import { createApp } from "vue";
import App from "./App";
import router from "./router/index.js";

let instance = null;
const render = () => {
  instance = createApp(App);
  instance.use(router).mount("#app");
};

// 如果当前不是在微前端的环境
if (!window.__POWERED_BY_QIANKUN__) {
  render();
}

export const bootstrap = async () => {
  console.log("vue3-bootstrap");
};

// props 获取主应用传递过来的参数
export const mount = async (props) => {
  console.log(props, '-=--');
  props.onGlobalStateChange((state, prev) => {
    // state: 变更后的状态; prev 变更前的状态
    console.log('变更state：',state, prev);
  });
  setTimeout(() => {
    props.setGlobalState({
      a: 2,
      b: 3
    });
  }, 2000);
  render();
  console.log("vue3-mount");
};

export const unmount = async () => {
  console.log("vue3-unmount", instance);
};
